<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      function getRandom(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值
      }
      var num = getRandom(1, 50);
      var ynum = prompt("请您输入一个数字");
      for (var i = 1; i <= 10; i++) {
        var j = 10 - i;
        if (ynum > num) {
          alert("数字大了，继续猜,你还剩" + j + "次机会");
          var ynum = prompt("输入一个数字");
        } else if (ynum < num) {
          alert("数字小了，继续猜,你还剩" + j + "次机会");
          var ynum = prompt("输入一个数字");
        } else {
          alert("牛逼");
          break;
        }
      }
    </script>
  </head>
  <body></body>
</html>
